修复:CORS 配置非法组合(通配源 + 携带凭证)#6
Open
joy717 wants to merge 1 commit into
Open
Conversation
`allow_origins=["*"]` combined with `allow_credentials=True` is an invalid CORS combination — browsers reject `Access-Control-Allow-Origin: *` on credentialed requests, and Starlette works around it by reflecting the request Origin, effectively allowing any site to send credentialed requests. This tool makes no use of browser-side credentials (the forum cookies are sent server-side from cookies.txt), so set allow_credentials=False to keep the open wildcard origin without the unsafe credential reflection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
lottery_server.py的 CORS 中间件:allow_origins=["*"]与allow_credentials=True是非法组合。浏览器禁止对携带凭证的请求返回Access-Control-Allow-Origin: *;Starlette 为了绕过这个限制,会改为回显请求的Origin并带上Access-Control-Allow-Credentials: true,等价于允许任意站点发起携带凭证的跨域请求。修改
本工具不依赖浏览器端凭证(论坛 cookie 是服务端从
cookies.txt读取并发送的),因此关闭allow_credentials即可保留开放的通配源,同时去掉不安全的凭证回显。🤖 Generated with Claude Code